﻿using System;
using System.Data;
using System.IO;
using WebUI.Models;

namespace WebUI.UserControls
{
    public partial class UCSlideMain : System.Web.UI.UserControl
    {
        public string displayshow = "";
        public string displaylink = "";
        public string displayimg = "";
        public string displaytext1 = "";
        public string displaytext2 = "";
        public string displaytext3 = "";
        public string bannerresult = "";
        public string bannercnt = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            WebComponent component = new WebComponent();

            string bannermain = "~/Uploads/XML/bannerMain.xml";
            // Banner Main
            using (DataSet dsmain = new DataSet())
            {
                int j = 1;
                if (!File.Exists(Server.MapPath(bannermain))) return;
                dsmain.ReadXml(Server.MapPath(bannermain));
                if (dsmain.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dsmain.Tables[0].Rows.Count; i++)
                    {
                        displayshow = dsmain.Tables[0].Rows[i]["DisplayShow"].ToString();
                        displaylink = dsmain.Tables[0].Rows[i]["DisplayLink"].ToString();
                        displayimg = dsmain.Tables[0].Rows[i]["DisplayImg"].ToString();
                        displaytext1 = dsmain.Tables[0].Rows[i]["DisplayText1"].ToString();
                        displaytext2 = dsmain.Tables[0].Rows[i]["DisplayText2"].ToString();
                        displaytext3 = dsmain.Tables[0].Rows[i]["DisplayText3"].ToString();
                        bannerresult = bannerresult + component.getBannerMain(displaylink, displayimg, displaytext1, displaytext2, displaytext3);

                        if (j == 1)
                            bannercnt = bannercnt + "<div class=\"item selected\">1</div>";
                        else
                            bannercnt = bannercnt + "<div class=\"item\">" + j.ToString() + "</div>";
                        j++;
                    }
                }
            }
        }
    }
}